#include "head.h"
#include "unistd.h"

#include "Progress_bar.h"
#include "guess_num.h"
#include "pyramid.h"
#include "grades.h"

typedef struct The_users
{
    char name[20];
    char pas[10];
} users;

void main()
{
    users user_1;
    strcpy(user_1.name, "lwq");
    strcpy(user_1.pas, "123");
    char in_name[20];
    char in_pas[10];
    int err;      // 判断错误次数
    int sign = 0; // 退出按钮
    int sign_1 = 0; // 退出switch
    int flog = 0; // 是否登录成功
    int mod = 0;  // 菜单页面模式选择
    while (1)
    {
        printf("请输入您的账号");
        scanf("%s", in_name);
        if (!strcmp(user_1.name, in_name))
        {
            printf("请输入您的密码");
            scanf("%s", in_pas);
            if (!strcmp(user_1.pas, in_pas))
            {
                printf("登录成功\n");
                flog = 1;
                break;
            }
            else
            {
                printf("密码错误\n");
                err++;
            }
        }
        else
        {
            printf("账号错误\n");
            err++;
        }
        if (err % 3 == 0)
        {
            printf("若要退出请按(-1) or 继续请按(1)");
            scanf("%d", &sign);
            if (sign == -1)
            {
                system("clear");
                break;
            }
            else if (sign == 1)
            {
                Progress_bar(5);
            }
            else
            {
                printf("滚蛋吧傻蛋！！！\r");
                fflush(stdout);
                sleep(3);
                system("clear");
                break;
            }
        }
    }
    if (flog == 1) // 进入菜单页面
    {
        while (1)
        {
            system("clear");
            printf("****************************\n");
            printf("*[猜数字小游戏]     (1)    *\n");
            printf("*[可控金字塔]       (2)    *\n");
            printf("*[随机生成学生成绩] (3)    *\n");
            printf("*退出请按          (-1)    *\n");
            printf("****************************\n");
            printf("请做出你的选择:");
            scanf("%d", &mod);
            system("clear");
            switch (mod)
            {
            case 1:
                printf("[猜数字小游戏]:\n");
                guess_num();
                printf("退出请按(-1)");
                scanf("%d", &sign);
                if (sign == -1)
                {
                    system("clear");
                    break;
                }

            case 2:
                printf("[可控金字塔]:\n");
                pyramid();
                printf("退出请按(-1)");
                scanf("%d", &sign);
                if (sign == -1)
                {
                    system("clear");
                    break;
                }

            case 3:
                grades();
                printf("退出请按(-1)");
                scanf("%d", &sign);
                if (sign == -1)
                {
                    system("clear");
                    break;
                }

            case -1:
                sign_1 = -1;
                break;

            default:
                break;
            }
            if (sign_1 == -1)
            {
                //system("clear");
                break;
            }
        }
    }
}